<template>
  <div class="cardModel">
    <el-row :gutter="20">
      <el-col class="col-model" v-for="(o, index) in v.cardData" :key="index" :span="8">
        <el-card shadow="hover" class="model-card">
          <div class="model-flex">
            <img :src="o.imgUrl" class="image" />
            <div>
              <span class="title">{{ o.title }}</span>
              <el-popover trigger="click" placement="bottom" width="60" :show-arrow="false">
                <p class="edit" @click="edit(o.userName)"> 编辑</p>
                <p class="delete" @click="del(o.userName)"> 删除</p>
                <!-- <p @click="">删除</p> -->
                <template #reference>
                  <el-icon class="more">
                    <MoreFilled />
                  </el-icon>
                </template>
              </el-popover>

              <div class="bottom">
                <time class="time">{{ o.c }}</time>
              </div>
              <span class="ot">{{ o.t }}</span>

            </div>
          </div>
          <el-divider />
          <div class="model-end">
            <div class="model-end">
              <el-avatar :size="26" :src="o.imgUrl" />
              <div class="f12666">{{ o.userName }}</div>
            </div>
            <div class="f12999">{{ o.time }}</div>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import { onMounted, onBeforeUnmount, reactive } from 'vue'
import Model1 from "@/assets/docs/model_1.svg";
import { useRouter } from "vue-router";
import pubsub from 'pubsub-js';
import dayjs from 'dayjs'
const router = useRouter();
// const currentDate = ref(new Date())

let CLOUDMODELCREATE = null as any
onMounted(() => {
  CLOUDMODELCREATE = pubsub.subscribe('CLOUDMODELCREATE', (_name, data) => {
    console.log(data)
    // console.log('有人发布了hello消息，hello消息的回调执行了',msgName,data)
    v.cardData.push({ title: data.name, c: data.desc, t: data.tag, time: dayjs().format() })
  })
})
onBeforeUnmount(() => {
  pubsub.unsubscribe(CLOUDMODELCREATE)
})

const v = reactive(
  {
    cardData: [{
      imgUrl: Model1,
      title: "ChatModel",
      c: "集成互联网亿万级信息节点，OpenGPT 巨量引擎，为您提供专业的AI助理服务。",
      t: 'GPT-4 (8K)',
      userImg: Model1,
      userName: '1',
      time: '12:15'
    }, {
      imgUrl: Model1,
      title: "ChatModel",
      c: "集成互联网亿万级信息节点，OpenGPT 巨量引擎，为您提供专业的AI助理服务。",
      t: 'GPT-4 (8K)',
      userImg: Model1,
      userName: '2',
      time: '12:15'
    }, {
      imgUrl: Model1,
      title: "ChatModel",
      c: "集成互联网亿万级信息节点，OpenGPT 巨量引擎，为您提供专业的AI助理服务。",
      t: 'GPT-4 (8K)',
      userImg: Model1,
      userName: '3',
      time: '12:15'
    },
    {
      imgUrl: Model1,
      title: "ChatModel",
      c: "集成互联网亿万级信息节点，OpenGPT 巨量引擎，为您提供专业的AI助理服务。",
      t: 'GPT-4 (8K)',
      userImg: Model1,
      userName: '4',
      time: '12:15'
    }, {
      imgUrl: Model1,
      title: "ChatModel",
      c: "集成互联网亿万级信息节点，OpenGPT 巨量引擎，为您提供专业的AI助理服务。",
      t: 'GPT-4 (8K)',
      userImg: Model1,
      userName: '5',
      time: '12:15'
    }]
  }

)

// 编辑
const edit = (p: string) => {
  //带参数跳转
  router.push({ path: '/intelligentService', query: { v: p } });
}
// 删除
const del = (p: string) => {
  console.log(12321)

  let newList = v.cardData.filter(e => e.userName !== p)
  console.log(newList);

  v.cardData = newList
}
</script>
<style>
.edit,
.delete {
  cursor: pointer;
}

.time {
  min-height: 54px;
}

.el-popover.el-popper {
  min-width: auto;
  border: none;
}

.cardModel {
  .image {
    width: 80px;
  }



  .el-divider--horizontal {
    margin: 16px 0;
  }

  .model-card {
    border-radius: 10px;
    background: var(--, #FFF);
    box-shadow: 0px 4px 12px 0px rgba(58, 51, 51, 0.05);
    border: none;


    .model-flex {
      display: flex;
      align-items: flex-start;
    }

    .more {
      float: right;
      cursor: pointer;
    }

    .model-end {
      display: flex;
      justify-content: space-between;
      align-items: center;
    }

    .title {
      color: #333;
      font-size: 18px;
      font-weight: 500;
    }

    .ot {
      color: #999;
      font-size: 12px;
      font-weight: 400;
    }
  }
}

.col-model {
  margin-bottom: 20px;
}

.time {
  color: #666;
  font-size: 14px;
  font-weight: 400;
  line-height: 18px;
}

.bottom {
  margin: 6px 0;
  line-height: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.button {
  padding: 0;
  min-height: auto;
}

.image {
  width: 100%;
  display: block;
  margin-right: 16px;
}

.f12666 {
  margin-left: 10px;
}
</style>
